package com.wulis.generator.config;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;


import static com.wulis.generator.utils.CommonUtil.getAuthor;

/**
 * @author WuliBao
 */
public class GeneratorGlobalConfig {

    /**
     * 代码生成配置
     *
     * @param datasourceConfig 数据源
     * @param projectConfig 项目配置
     * @return FastAutoGenerator
     */
    public static FastAutoGenerator get(DatasourceConfig datasourceConfig, ProjectConfig projectConfig) {
        return FastAutoGenerator
            .create(new DataSourceConfig.Builder(datasourceConfig.getUrl(), datasourceConfig.getUsername(),
                datasourceConfig.getPassword()).driverClassName(datasourceConfig.getDriverClassName()))
            // 全局配置
            .globalConfig(builder -> builder
                // 指定输出目录
                .outputDir(projectConfig.getProjectPath() + "/src/main/java")
                // 设置作者
                .author(getAuthor())
                // 开启 swagger 模式
                .enableSpringdoc()
                // 关闭打开输出目录
                .disableOpenDir());
    }
}
